<template>
  <el-dialog class="audit-dialog-box" width="400px" title="题目审核" :visible.sync="dialogFormVisible" @close='$refs.formRef.validate()'>
    <el-form :model="form" ref="formRef">
      <el-form-item prop="chkState">
        <el-radio v-model="form.chkState" :label="1">通过</el-radio>
        <el-radio v-model="form.chkState" :label="2">拒绝</el-radio>
      </el-form-item>
      <el-form-item prop="chkRemarks">
        <el-input v-model.trim="form.chkRemarks" type="textarea" placeholder="请输入审核意见"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogFormVisible = false">取 消</el-button>
      <el-button type="primary" @click="submitAuditData">确 认</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { choiceCheck } from '@/api/hmmm/questions'

export default {
  data(){
    return {
      form: {
        chkState: 1,
        chkRemarks: ''
      },
      dialogFormVisible: false
    }
  },
  methods: {
    // 提交预览框
    async submitAuditData(){
      // id: 当前题的id
      // chkState 1通过 2不通过
      // chkRemarks: 审核原因
      if(this.form.chkRemarks === ''){
        return this.$message.warning('审核意见不可为空')
      }
      try{
        await choiceCheck(this.form)
      }catch(err){
        console.log(err)
        this.$message.error('啊哦，执行审核失败..')
      }
      this.dialogFormVisible = false
    },
    // 打开预览框
    openAuditDialog(id){
      this.form.id = id
      this.dialogFormVisible = true
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.audit-dialog-box {
  .dialog-footer {
    text-align: right;
  }
}
</style>